/**
 * StatCard.java - 2012-10-10
 *
 * Licensed Property to China UnionPay Co., Ltd.
 * 
 * (C) Copyright of China UnionPay Co., Ltd. 2010
 *     All Rights Reserved.
 *
 * Project Info: China UnionPay Internet Acquiring Project
 * 
 * Modification History:
 * =============================================================================
 *   Author         Date          Description
 *   ------------ ---------- ---------------------------------------------------
 *        
 * =============================================================================
 */
package com.lijin.study.java.parseacct;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.lijin.study.java.util.FileLineProcessor;
import com.lijin.study.java.util.FileUtil;

/**
 * Description: 
 *
 * (C) Copyright of China UnionPay Co., Ltd. 2010.
 *
 */
public class StatCard {

	public static void main(String[] args) throws Exception {
		final Set<String> s1 = new HashSet<String>();
		final Set<String> s2 = new HashSet<String>();
		long start = System.currentTimeMillis();
		final BufferedWriter writer = new BufferedWriter(
				new OutputStreamWriter(new FileOutputStream(new File("D:\\工作目录\\02.日常工作\\生产数据处理\\报表系统日志\\result.txt")), "GBK"));
		
		File f1 = new File("D:\\工作目录\\02.日常工作\\生产数据处理\\报表系统日志\\TBL_UPONL_CARD_INF.txt");
		FileUtil.readFileByLine(f1, new FileLineProcessor() {
			@Override
			public void processLine(String line) {
				s1.add(line);
				if (s1.size() == 100000) {
					System.out.println("----->" + s1.size());
					File f2 = new File("D:\\工作目录\\02.日常工作\\生产数据处理\\报表系统日志\\TBL_UPHIS_CARD_BAK.txt");
					try {
						FileUtil.readFileByLine(f2, new FileLineProcessor() {
							@Override
							public void processLine(String line) {
								try {
									if (s1.contains(line)) {
										writer.write(line);
										writer.newLine();
										s1.remove(line);
									}
								} catch (Exception e) {
									e.printStackTrace();
								}
							}
						}, "GBK", 0);
					} catch (Exception e) {
						e.printStackTrace();
					}
					System.out.println("----->" + s1.size());
					s2.addAll(s1);
					System.out.println("----->" + s2.size());
					s1.clear();
				}
			}
		}, "GBK", 0);
		
		if (s1.size() > 0) {
			System.out.println("last----->" + s1.size());
			File f2 = new File("D:\\工作目录\\02.日常工作\\生产数据处理\\报表系统日志\\TBL_UPHIS_CARD_BAK.txt");
			FileUtil.readFileByLine(f2, new FileLineProcessor() {
				@Override
				public void processLine(String line) {
					try {
						if (s1.contains(line)) {
							writer.write(line);
							writer.newLine();
							s1.remove(line);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}, "GBK", 0);
			
			System.out.println("last----->" + s1.size());
			s2.addAll(s1);
			System.out.println("last----->" + s2.size());
			s1.clear();
		}
		writer.flush();
		writer.close();
		System.out.println("Tm--->" + (System.currentTimeMillis() - start));
		
		List<String> l = new ArrayList<String>(s2);
		FileUtil.writeFileByLine(new File("D:\\工作目录\\02.日常工作\\生产数据处理\\报表系统日志\\result2.txt"), l, "GBK");
	}
	
}
